from pydantic import BaseModel, EmailStr
from typing import Optional, List
from datetime import date

class ScholarFullResponse(BaseModel):
    # Basic Info
    program: Optional[str]
    year: Optional[int]
    student_number: Optional[str]
    first_name: Optional[str]
    preferred_name: Optional[str]
    last_name: Optional[str]
    default_email: Optional[str]
    alternate_email: Optional[str]
    university_status: Optional[str]
    date_of_birth: Optional[date]
    gender: Optional[str]
    school_code: Optional[str]
    school_name: Optional[str]
    gateway_school: Optional[str]
    indigenous_student: Optional[str]
    start_date:Optional[date]
    end_date:Optional[date]
    scholar_type: Optional[str]  # original, late, replacement

    # Dietary & Medical
    dietary_preference: Optional[str]
    dietary_allergies: Optional[str]
    dietary_religious: Optional[str]
    medical_allergies: Optional[str]

    # IT Placement (multiple)
    ite_number: Optional[int]
    sponsor_name: Optional[str]
    department: Optional[str]
    supervisors: Optional[str]
    ite_start: Optional[date]
    ite_end: Optional[date]
    ite_details_input_date: Optional[date]
    ite_input_in_time: Optional[bool]
    latest_start_date: Optional[date]
    expected_finish_date: Optional[date]
    start_date_met: Optional[bool]
    end_date_met: Optional[bool]
    it_change_approved: Optional[str]
    pd_agreement_submission_date: Optional[date]
    placement_mid_point: Optional[date]
    mpc_call_date: Optional[date]
    mpc_call_on_time: Optional[str]
    mpc_document_due_date: Optional[date]
    mpc_submitted_date: Optional[date]
    mpc_submitted_on_time: Optional[str]
    end_of_it_presentation_date: Optional[date]
    end_of_it_input_date: Optional[date]
    it_presentation_completed_ontime: Optional[str]
    unsw_attendee_on_presentation: Optional[str]
    sponsor_evaluation_sent_to_sponsor_date: Optional[date]
    sent_before_end_of_placement: Optional[bool]
    sponsor_completed_date: Optional[date]
    scholar_comment: Optional[str]
    sponsor_evaluation_completed_on_time: Optional[bool]
    placement_completed_date: Optional[date]
    placement_grade: Optional[str]
    placement_performance: Optional[str]
    grade_updated: Optional[str]
    grade_updated_date: Optional[date]
    class Config:
        from_attributes = True


class ScholarBase(BaseModel):
    program_id: Optional[str]
    student_id: Optional[str]
    first_name: Optional[str]
    last_name: Optional[str]
    preferred_name: Optional[str]
    gender: Optional[str]
    date_of_birth: Optional[date]
    school_code: Optional[str]
    dietary_pref_id: Optional[int]
    dietary_allergy: Optional[str]
    dietary_religious: Optional[str]
    medical_allergies: Optional[str]
    email: Optional[EmailStr]
    current_email: Optional[EmailStr]
    program_start_date: Optional[date]
    program_finish_date: Optional[date]

class ScholarCreate(ScholarBase):
    scholar_id: str

class ScholarUpdate(ScholarBase):
    pass

class ScholarResponse(ScholarBase):
    scholar_id: str
    class Config:
        from_attributes = True

class ScholarFullListResponse(BaseModel):
    total: int
    scholars: List[ScholarFullResponse]